package com.ewhale.feitengguest.ui.user.task

import android.os.Bundle
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.dto.SignInDto
import com.ewhale.feitengguest.presenter.user.task.SignInPresenter
import com.ewhale.feitengguest.view.user.task.SignInView
import com.simga.library.activity.MBaseActivity
import kotlinx.android.synthetic.main.activity_sign_in.*

/**
 * 作者：SimGa
 * 日期：2019/12/26
 * 时间：15:10
 * 包名：com.ewhale.feitengguest.ui.user.task
 */
class SignInActivity : MBaseActivity<SignInPresenter>(), SignInView {
    override fun getViewId(): Int {
        return R.layout.activity_sign_in
    }

    override fun isUseBaseTitleBar(): Boolean {
        return true
    }

    override fun init(savedInstanceState: Bundle?) {
        setTitle("签到")
        presenter.getSignInDetail()
    }

    override fun showSignDetail(signInDto: SignInDto?) {
        tv_yesterdayStatus.text = if (signInDto!!.yesterDaySign == 1) "已签到" else "未签到"
        tv_todayStatus.text = if (signInDto.todaySign == 1) "已签到" else "未签到"
        btn_sign.apply {
            text =  if (signInDto.todaySign == 1) "已签到" else "签到"
            isEnabled = signInDto.todaySign == 0
        }
        tv_yesterdayAmount.text = "+" + signInDto.yesterDayAmount.stripTrailingZeros().toPlainString() + "元"
        tv_todayAmount.text = "+" + signInDto.todayAmount.stripTrailingZeros().toPlainString() + "元"
        tv_tomorrowAmount.text = "+" + signInDto.tomorrowAmount.stripTrailingZeros().toPlainString() + "元"
    }

    override fun sign() {
        showToast("签到成功")
        tv_todayStatus.text = "已签到"
        btn_sign.apply {
            text =  "已签到"
            isEnabled = false
        }
    }

    override fun initListener() {
        super.initListener()
        btn_sign.setOnClickListener {
            presenter.sign()
        }
    }

    override fun showProLoading() {
        showLoading()
    }

    override fun dimissProLoading() {
        dismissLoading()
    }

    override fun showErrorMessage(postCode: Int, code: String?, message: String?) {
        showErrorMsg(code, message)
    }

    companion object {
        @JvmStatic
        fun open(mContent: MBaseActivity<*>) {
            mContent.startActivity(null, SignInActivity::class.java)
        }
    }
}
